<?php
namespace app\admin\controller;

use \app\admin\controller\Base;
use \think\Db;
use think\facade\Request;

class Productbrand extends  Base
{
	public function index()
    {
    	
		$brands = DB::name('goods_brand')->select();
		$this->assign('brands',$brands);
 		return $this->fetch();
    }
	
	//品牌添加
	public function add()
	{
		if(Request::isAjax())
		{
			$post  = input('post.');
			$post['create_time'] = time();
			$id = Db::name('goods_brand')->insertGetId($post);
			if($id>0)
			{
				echo 20000;exit;
			}
			echo 20001;exit;
		}
		
		$brands = DB::name('goods_brand')->select();
		
		$this->assign('brands',$brands);		
		return $this->fetch();	
	}
	
	//品牌删除
	public function articledelete()
	{
		$id =  input('post.id');
//		echo $id;exit;
		
		$re = Db::name('goods_brand')->where('id',$id)->delete();
//		echo $re;exit;
		if($re>0)
		{
			//删除失败
			echo 20000;exit;
		}
		//删除失败
		echo 200003;exit;
	}
	
	//更新分类
	public function update()
	{
		//选中的分类
		$id = input('get.id');
		$currencate = Db::name('goods_brand')->where('id',$id)->find();
		$this->assign('currencate',$currencate);
		//所有分类数据
		$brands = DB::name('goods_brand')->select();
		$this->assign('brands',$brands);	
		//dump($get);
		if(Request::isAjax())
		{
			$post  = input('post.');
//			print_r($post);die;
			$id=$post['id'];
//			unset($post['id']);
			$re = DB::name('goods_brand')->where('id',$id)->update($post);
//			echo $re;die;
			if($re>0)
			{
				echo 20000;exit;
			}
			echo 20001;exit;
		}
		return $this->fetch();
	}
	
}
?>